package com.zhong.system.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhong.system.domain.SysUserRole;
import com.zhong.system.mapper.SysUserRoleMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
@RequiredArgsConstructor
public class SysUserRoleService extends ServiceImpl<SysUserRoleMapper, SysUserRole> {

    public List<SysUserRole> findListByUserId(String userId){
        return list(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId,userId));
    }

    public List<SysUserRole> findListByRoleId(String roleId){
        return list(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getRoleId,roleId));
    }

    public boolean removeByRoleIdAndUserIds(String roleId, String[] userIds){
        return remove(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getRoleId,roleId).in(SysUserRole::getUserId, Arrays.asList(userIds)));
    }

    public boolean removeByUserId(String userId){
        return remove(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId,userId));
    }

    public boolean removeByUserIds(String[] userIds){
        return remove(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId,Arrays.asList(userIds)));
    }
}
